package es.tikitaka.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import es.tikitaka.dao.ProvinciaDicService;
import es.tikitaka.dictionary.ProvinciaDic;

/**
 * 
 * @author Saúl Domínguez
 * @since 2010
 * @category PFC
 */
@Name("provinciaService")
public class ProvinciaDicServiceImpl implements ProvinciaDicService {

	@In
	EntityManager em;

	public ProvinciaDicServiceImpl() {
		// TODO Auto-generated constructor stub
	}

	@Begin(join = true)
	@SuppressWarnings("unchecked")
	public List<ProvinciaDic> getList() {

		List<ProvinciaDic> list = null;
		try {
			list = em.createQuery(
					"select p from ProvinciaDic p order by p.provincia")
					.getResultList();
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public boolean delete(Integer id) {
		boolean correcto;
		try {
			ProvinciaDic prov = em.getReference(ProvinciaDic.class, id);
			em.remove(prov);
			em.flush();
			correcto = true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			correcto = false;
		}
		return correcto;
	}

	public boolean save(ProvinciaDic prov) {
		boolean correcto;
		try {
			em.persist(prov);
			em.flush();
			correcto = true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			correcto = false;
		}
		return correcto;
	}
}
